import logging

from lib.utils.utils import *
from lib.utils.jsoncfg import jsonCfg
from lib.utils.justmatched import justMatched

class baseStnTrigger:
    jsonCfg = trig = buffer = justMatchedObj = userAgent = None
    
    def __init__(self, jsonCfg, trig, userAgent, buffer, loggerName):
        self.jsonCfg = jsonCfg
        self.buffer = buffer
        self.trig = trig
        self.loggerName = loggerName
        self.userAgent = userAgent
        self.justMatchedObj = justMatched()
        self.logger =  logging.getLogger(self.loggerName + '.trigger')

    def run(self):
        pass
    
    def callTrigger(self):
        if('trig' in self.trig):
            trig = self.trig['trig']
            # if not a list...make it
            if(type(trig) is not list): trig = [trig]
            
            for item in trig:
                # get notify type
                trigType=self.jsonCfg.evalGet(item, 'type', 'trig')
                
                # instance and call
                trigClass = getTrigger(trigType)
                trigClass = trigClass(self.jsonCfg, item, self.userAgent, self.buffer, self.loggerName + '.trigger')
                trigClass.run()
        
        return False
    
    def callNotifier(self):
        if('notify' in self.trig):
            notify = self.trig['notify']
            # if not a list...make it
            if(type(notify) is not list): notify = [notify]
            
            for item in notify:
                # get notify type
                notifyType=self.jsonCfg.evalGet(item, 'type', 'notify')
                
                # instance and call
                notifierClass = getNotifier(notifyType)
                notifierClass = notifierClass(self.jsonCfg, item, self.buffer, self.loggerName + '.trigger')
                notifierClass.run()
        
        return False
